<?php

/**
 * Enter description here ...
 * @author rampelli
 *
 */
class Application_Model_ClassModel
{
     protected $_dbTable;


    public function getdbTable() {
         if (null === $this->_dbTable) {
            $this->setDbTable('Application_Model_DbTable_ClassModel');
        }
        return $this->_dbTable;
    }

    public function setdbTable($dbTable) {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function save($data)
    {
        return $this->getdbTable()->insert($data);
    }
  
  	/*
  	 * 
  	 *  Retrives all class existing in the school
  	 */
    public function fetchAll()
    {
    	return $this->getdbTable()->fetchAll();
    }

    public function getStudentsListByClassId($data)
    {
        $db = Zend_Registry::get ( 'db' );
        if($data['class_id'] != null){
        $query = "SELECT sm.id,sm.fname,sm.lname FROM `student_master` AS sm , `student_class` AS sc WHERE sm.`id` = sc.`student_id` AND sc.`class_id` = ".$data['class_id']." AND sc.`academic_id` = ".$data['academic_id']."";
        }else{
        	$query = "SELECT sm.id,sm.fname,sm.lname FROM `student_master` AS sm , `student_class` AS sc WHERE sm.`id` = sc.`student_id` AND sc.`class_id` = '1' AND sc.`academic_id` = ".$data['academic_id']."";
        }
         $stmt = $db->query ( $query );
    	return  $stmt->fetchAll();
    }
}

